package com.feihao.zhou.TCP.demoFileUpLoadUseThread;

import java.io.*;
import java.net.Socket;

public class ClientDemo001 {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8808);

        //读取本地文件：
        BufferedInputStream bis = new BufferedInputStream(
                new FileInputStream("D:\\IdeaProjects\\Job-code\\day16-code-NET\\dir\\day14-网络编程01.pdf"));

        //创建网络字节输出流，将文件写入服务器：
        OutputStream os = socket.getOutputStream();
        //一读一写：本地文件流读取，网络写入流写入：
        int b;
        byte[] bytes = new byte[1024];

        while ((b = bis.read(bytes)) != -1) {
            //网络流写入：
            os.write(bytes, 0, b);
        }

        //写完后给服务器写完的标志：
        socket.shutdownOutput();

        //读取服务器回传信息：
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }

        //关闭资源：
        socket.close();
        bis.close();
        br.close();
    }
}
